package com.hs.hlw.credit.system.web.controller.api;

import com.hs.hlw.credit.system.business.dto.ResponseDto;
import com.hs.hlw.credit.system.business.dto.SubmissionFormFieldDto;
import com.hs.hlw.credit.system.business.dto.UserDto;
import com.hs.hlw.credit.system.business.service.SubmissionFormFieldService;
import com.hs.hlw.credit.system.web.util.RequestUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * SubmissionFormFieldController
 * @author zhb
 * @date 2018/11/21
 */
@RestController
@RequestMapping("/api/submission/form/field")
public class SubmissionFormFieldController {
    private @Autowired SubmissionFormFieldService submissionFormFieldService;

    @PostMapping(path = "update1")
    @ApiOperation(value = "更新文本输入规则", notes = "更新文本输入规则")
    public ResponseDto update1(@RequestBody @Valid SubmissionFormFieldDto.Update1 data, HttpServletRequest request) {
        UserDto user = RequestUtil.getUserFromSession(request);
        return submissionFormFieldService.update1(data, user);
    }

    @PostMapping(path = "update2")
    @ApiOperation(value = "更新数值输入规则", notes = "更新数值输入规则")
    public ResponseDto update2(@RequestBody @Valid SubmissionFormFieldDto.Update2 data, HttpServletRequest request) {
        UserDto user = RequestUtil.getUserFromSession(request);
        return submissionFormFieldService.update2(data, user);
    }

    @PostMapping(path = "update3")
    @ApiOperation(value = "更新维表选择规则", notes = "更新维表选择规则")
    public ResponseDto update3(@RequestBody @Valid SubmissionFormFieldDto.Update3 data, HttpServletRequest request) {
        UserDto user = RequestUtil.getUserFromSession(request);
        return submissionFormFieldService.update3(data, user);
    }

    @PostMapping(path = "update4")
    @ApiOperation(value = "更新日期选择规则", notes = "更新日期选择规则")
    public ResponseDto update4(@RequestBody @Valid SubmissionFormFieldDto.Update4 data, HttpServletRequest request) {
        UserDto user = RequestUtil.getUserFromSession(request);
        return submissionFormFieldService.update4(data, user);
    }

    @GetMapping(path = "getFiledListByForm")
    @ApiOperation(value = "根据表单获取字段列表", notes = "根据表单获取字段列表")
    public ResponseDto getFiledListByForm(@RequestParam @ApiParam(value = "表单id", required = true) Integer formId) {
        return submissionFormFieldService.getFiledListByForm(formId);
    }
}